package net.ghsoft.Convert
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	import mx.events.FlexEvent;
	
	import spark.components.Image;
	
	import net.ghsoft.AppGlobal;
	import net.ghsoft.SetupGlobal;
	import net.ghsoft.Convert.ConvertTemperature;
	
	public class MyTemperatureSmallImage extends Image
	{
		public function MyTemperatureSmallImage()
		{
			addEventListener(FlexEvent.CREATION_COMPLETE, MyTemperatureSmallImage_creationCompleteHandler);
			super();
		}
		
		protected function MyTemperatureSmallImage_creationCompleteHandler(event:FlexEvent):void
		{
			// TODO Auto-generated method stub
			var strURL:String = AppGlobal.WebURL;
			
			if(SetupGlobal.TemperautleUnitLocal != "F")
			{
				strURL = strURL.replace("Weather.swf", "assets/Temperature/Celsius.png");
			}
			else
			{
				strURL = strURL.replace("Weather.swf", "assets/Temperature/Fahrenheit.png");
			}
			
			var loader:Loader = new Loader();
			//这里需要注意的是 不是_loader.addEventListener  这样是没有效果的
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderUrl);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, IoError);
			loader.addEventListener(IOErrorEvent.IO_ERROR, IoError);
			//这里说一个技巧  当url 中有中文字体的话 使用encodeURI方法 如果没有 则可以不加
			loader.load(new URLRequest(strURL));
			
			function loaderUrl(e:Event):void
			{
				var bmp:Bitmap = e.currentTarget.content as Bitmap;
				if(bmp != null)
				{
					source = bmp;
				}
			}
			function IoError(e:IOErrorEvent):void
			{
//				Alert.show(e.text);
			}
		}
	}
}